import 'package:environmental_les_app/common/routes/route_names.dart';
import 'package:flutter_clx_base/flutter_clx_base.dart';

import 'index.dart';

class TestMenuPage extends GetView<TestMenuController> {
  const TestMenuPage({super.key});

  // 主视图
  // 主视图
  Widget _buildView() {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          TextField(
            controller: controller.urlController,
            keyboardType: TextInputType.url,
            decoration: const InputDecoration(
              labelText: '输入网址',
              hintText: 'https://www.example.com',
              border: OutlineInputBorder(),
            ),
          ),
          const SizedBox(height: 12),
          ElevatedButton(
            onPressed: () {
              String url = controller.urlController.text.trim();
              if (url.isEmpty) return;
              if (!url.startsWith('http')) {
                url = 'https://$url';
              }
              Get.toNamed(AppRoutes.webPage, arguments: {'url': url});
            },
            child: const Text(
              '打开网页',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TestMenuController>(
      init: TestMenuController(),
      id: "test_menu",
      builder: (_) {
        return MyScaffold(
          title: "测试菜单",
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
